#define _CRT_SECURE_NO_WARNINGS 1



#include<stdio.h>


int main()
{
	int arr[2000] = { 0 }, i = 0, j = 0, sum = 0, count = 0, n = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++)
		arr[i] = i + 1;
	for (i = 0; 1; i++)
	{
		if (arr[i] == 0)
			i = 0;
		sum++;
		if (sum == 3)
		{
			sum = 0;
			count++;
			if (count == n)
			{
				printf("%d\n", arr[i]);
				break;
			}
			for (j = i; j < n; j++)
				arr[j] = arr[j + 1];
			i--;
		}
	}

	return 0;
}